package cn.iocoder.yudao.module.erp.dal.mysql.invoiceintegration;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.invoiceintegration.vo.InvoiceIntegrationPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.checkout.CheckOutDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.invoiceintegration.InvoiceIntegrationDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * 发票整合 Mapper
 *
 * @author ls
 */
@Mapper
public interface InvoiceIntegrationMapper extends BaseMapperX<InvoiceIntegrationDO> {

    default PageResult<InvoiceIntegrationDO> selectPage(InvoiceIntegrationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InvoiceIntegrationDO>()
                .eqIfPresent(InvoiceIntegrationDO::getIntegrationId, reqVO.getIntegrationId())
                .eqIfPresent(InvoiceIntegrationDO::getOrderTotalPric, reqVO.getOrderTotalPric())
                .eqIfPresent(InvoiceIntegrationDO::getOrderNum, reqVO.getOrderNum())
                .eqIfPresent(InvoiceIntegrationDO::getStatus, reqVO.getStatus())
                .eqIfPresent(InvoiceIntegrationDO::getPayStatus, reqVO.getPayStatus())
                .eqIfPresent(InvoiceIntegrationDO::getInvoiceStatus, reqVO.getInvoiceStatus())
                .inIfPresent(InvoiceIntegrationDO::getProcessInstanceId,reqVO.getProcessInstanceIds()) // 添加 processInstanceIds 过滤条件
                .betweenIfPresent(InvoiceIntegrationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InvoiceIntegrationDO::getCreateTime));
    }

    default InvoiceIntegrationDO selectByNo(String no){
        return selectOne(InvoiceIntegrationDO::getIntegrationId,no);
    }

    @Update("update erp_invoice_integration set invoice_status = #{invoiceStatus} where id = #{checkInvoiceId}")
    void updateStatusByCheckInvoiceId(String checkInvoiceId, String invoiceStatus);

    @Update("update erp_invoice_integration set pay_status = #{payStatus} where id = #{checkInvoiceId}")
    void updatePayStatusByCheckInvoiceId(String checkInvoiceId, String payStatus);
}